package com.sugeun.alarm;

import java.util.List;

import com.sugeun.stopwatch.R;



import android.content.Context;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CheckedTextView;
import android.widget.TextView;
import android.widget.ToggleButton;


public class AlarmAdapter extends ArrayAdapter<Alarm>
{
	private final String TAG = "AlarmAdapter";
	private List<Alarm> mItems;
	private LayoutInflater mInflater;
	
	
	public AlarmAdapter(Context context, int resource, List<Alarm> items) 
	{
		super(context, resource, items);
		mItems = items;
		mInflater = LayoutInflater.from(context);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) 
	{
		if(convertView == null)
		{
			convertView = mInflater.inflate(R.layout.alarm_row, null);
		}
		//convertView.setClickable(true);
		Alarm alarm = mItems.get(position);
		convertView.setTag(alarm);
		Log.d(TAG, "alarm.getId : "+alarm.getId());
		CheckedTextView cyv = (CheckedTextView)convertView.findViewById(R.id.button_toggle);
		TextView alarm_time = (TextView)convertView.findViewById(R.id.time);
		TextView alarm_days_of_week = (TextView)convertView.findViewById(R.id.days_of_week);
		TextView alarm_message = (TextView)convertView.findViewById(R.id.message);
		
//		Log.d(TAG, "alarm.getMinutes() : "+alarm.getMinutes());		
		cyv.setChecked(Boolean.valueOf(alarm.getEnabled()));
		alarm_time.setText((alarm.getHour()+":"+alarm.getMinutes()));
		alarm_days_of_week.setText(alarm.getDays_of_week());
		alarm_message.setText(alarm.getMessage());
		

		
		return convertView;
	}	
}
